package com.promote.sort;

/**
 * @ClassName FindNumberInArray
 * Description 二维数组中的查找
 * @Author lizihao
 * Date 2021/3/27 14:32
 * @Version 1.0
 **/
public class FindNumberInArray {


    public boolean findNumberIn2DArray(int[][] nums, int target) {

        if (nums == null || nums.length == 0 || nums[0].length == 0) {
            return false;
        }
        int rows = nums.length;
        int columns = nums[0].length;
        int row = 0;
        int column =columns - 1 ;
        while (row < rows && column >= 0) {
            int num = nums[row][column];
            if (num == target) {
                return true;
            }else if (num > target) {
                column--;
            }else {
                row++;
            }
        }
        return false;
    }
}
